//
//  CollectionCell.m
//  Tang
//
//  Created by 352324497@qq.com on 15/12/3.
//  Copyright © 2015年 352324497@qq.com. All rights reserved.
//

#import "CollectionCell.h"
#import "CollectionViewCell.h"
@implementation CollectionCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = NO;
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        layout.minimumInteritemSpacing = 10;
        layout.minimumLineSpacing = 10;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        self.collectionViewVc = [[UICollectionView alloc]initWithFrame:CGRectMake(10 * Kx6, 10 * Kx6, KWidth, 100 * Kx6) collectionViewLayout:layout];
        self.collectionViewVc.dataSource = self;
        self.collectionViewVc.delegate = self;
        self.collectionViewVc.showsHorizontalScrollIndicator = NO;
        [self.collectionViewVc registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        self.collectionViewVc.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_collectionViewVc];
        self.modelArray = [NSMutableArray array];
    }
    return self;
}

-(void)setCellWithArray:(NSMutableArray *)array
{
    if (array.count != 0)
    {
        self.modelArray = array;
//        NSLog(@"&&&&& %ld", self.modelArray.count);
        [self.collectionViewVc reloadData];
    }
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
//    NSLog(@"****** %ld", self.modelArray.count);
    if (self.modelArray.count != 0)
    {
        return self.modelArray.count;
    }
    return 0;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(100 * Kx6, 100 * Kx6);
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    if (cell == nil)
    {
        cell = [[CollectionViewCell alloc]init];
    }
    if (self.modelArray.count != 0)
    {
        CollectionModel *model = self.modelArray[indexPath.item];
        cell.model = model;
    }
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.delegate respondsToSelector:@selector(jumpToControllerWithIndexPath:)])
    {
        [self.delegate jumpToControllerWithIndexPath:indexPath];
    }
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
